package com.yn.springboot.demo_locale.controller;

import com.yn.springboot.demo_locale.utils.MessageSourceUtil;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName: TestController
 * @Description: 测试控制器
 * @author: 王胜
 * @date 2021/4/1
 * @Version: 1.0
 **/
@RestController
@RequestMapping("/")
public class TestController {
    @Resource
    MessageSource messageSource;
    @GetMapping("/")
    public String getIndex(){
        return messageSource.getMessage("hello.name",null, LocaleContextHolder.getLocale());
    }
    @PostMapping("/")
    public String postIndex(){
        return messageSource.getMessage("hello.name",null, LocaleContextHolder.getLocale());
    }
    @GetMapping("/mes")
    public String getMessage(){
        return MessageSourceUtil.getMessage("hello.name");
    }
    @PostMapping("/mes")
    public String postMessage(){
        return MessageSourceUtil.getMessage("hello.name");
    }
}
